package cc.orange.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

import java.util.ArrayList;

import androidx.viewpager.widget.PagerAdapter;
import cc.orange.entity.PersonMsgEntity;

/**
 * Created by CM on 2022/11/3.
 */
public class PersonImgAdapter extends PagerAdapter {

      private ArrayList<PersonMsgEntity.Data.Image> imageList;
      private Context context;

      public PersonImgAdapter(ArrayList<PersonMsgEntity.Data.Image> imageList,Context context) {
         this.context = context;
         this.imageList = imageList;

      }
      // 需要实现以下四个方法

      @Override
      public int getCount() {
         return imageList.size();
      }

      @Override
      public boolean isViewFromObject(View view, Object object) {
         // 判断view和Object对应是否有关联关系
//         if (view == object) {
//            return true;
//         } else {
//            return false;
//         }
          return view == object;
      }

      @Override
      public Object instantiateItem(ViewGroup container, int position) {
         ImageView img = new ImageView(context);
         img.setScaleType(ImageView.ScaleType.CENTER_CROP);
          Glide.with(context).load(imageList.get(position).getImage())
                  .into(img);
          container.addView(img);
         return img;
      }

      @Override
      public void destroyItem(ViewGroup container, int position, Object object) {
         // 销毁对应位置上的Object
         // super.destroyItem(container, position, object);
          container.removeView(container);
      }
   }
